import JSEncrypt from 'jsencrypt';

// 生成的公钥： 用于数据加密
const publicKey = `MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDBXCZhYtIxs2ye7YmJ/uxBD7CjBOoccV/b44OhJGsz6ssWDBCUDrHUy4q6ZVew8a4JEmHcaxurQWkGYIF1E/+rpBQkU6aOOt8Gyi097VcoZqHs3mZKBKqbE37kAAoQhloTNYRe07wAJIQ4GxtykcTwj4tTyps4lB8wHmJGV7NXuwIDAQAB`;
// 生成的私钥 ： 用于数据解密
const priveteKey = `MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMFcJmFi0jGzbJ7tiYn+7EEPsKME6hxxX9vjg6EkazPqyxYMEJQOsdTLirplV7DxrgkSYdxrG6tBaQZggXUT/6ukFCRTpo463wbKLT3tVyhmoezeZkoEqpsTfuQAChCGWhM1hF7TvAAkhDgbG3KRxPCPi1PKmziUHzAeYkZXs1e7AgMBAAECgYAy5bHIor2XjZZDA13X8D16JsolLy78y68i73F/olmBsgVBSW23u2J+FBHxXKnHjuZzxt3xqlP/MVmW7yJEkj4TF9GtOmUYA84pvNHgRQA4n+2KlzS4O0lluXFZaiw8CI9+15EjMHUkyPh8TgoHxOhhVocCAYeoau85oCDVq87SOQJBAO7eWh1fhuwg3XiNMlVzkZw8/b5mDKVBZJ1ZCSVmnxCQj+ysp92PwLfA2AsPBhuTwC1sGeASVXBPL/lrvyIq7fcCQQDPOkGFta6oFxKsdv9Oz5sAvB/kXs6I5L0HzHKcs+Hu8hQiVXhYEMac7cxEIYdSj0yBhIdyGb0RNXOP/rzM9wNdAkBBYzSf3cp9UPHPUjd5FM3DSx7aw+yqQCBewkSyrEjWq/v5+blp+TP0GSIKxO4TFnsA9BqRL/ObbtHfIRONMts5AkEAx93PHlAp4VNHnnGzMmcHf8DyHYfXOa8sJl5o2HyiV5zCEI9Q39dmSCsOjVOtOdKeHnkdTc5HTVa5W9N8c092vQJBANB+uja9/SofjqLi3MJxQixQZPGg5HbwnDyl1RbqQ43cDo/SMY3TeHwAbws0CTXvG3Mj7i9Bc3cH7kkly46Zf9c=`;

export const encryptData = function (data) {
  //创建实例
  const encryptor = new JSEncrypt();
  //设置公钥
  encryptor.setPublicKey(publicKey);
  //对数据进行加密
  return encryptor.encrypt(data);
};

export const decryptedData = function (data) {
  //创建实例
  const decryptor = new JSEncrypt();
  //设置私钥
  decryptor.setPrivateKey(priveteKey);
  //对数据进行解密
  return decryptor.decrypt(data);
};
